﻿using OpenBlock.Block;
using OpenBlock.Core;
using OpenBlock.Core.Event.HUDRequest;
using OpenBlock.Entity;
using OpenBlock.Entity.Player;
using OpenBlock.Terrain;
using OpenBlock.Utils;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;

namespace OpenBlock.Item.Items
{
    public class Brush : IUsableItem, IConfigurableItem
    {
        public string Name => "Brush";

        public int MaxStackSize => 1;

        public Brush()
        {

        }

        public Sprite GetIcon(ItemState state)
        {
            return GameManager.Instance.brushSprite;
        }

        public void OnConfigue(ItemState state)
        {
            GameManager.Instance.eventQueue.SendEvent(new OpenColorPaletteEvent(state));
        }

        public void OnUse(ItemStack stack, BlockState at, PlayerObj player, Vector3Int readyPlaceBlockPos)
        {
            var state = stack.Item;
            player.world.level.SetBlock(BlockState.RGB(state.GetProperty("RGB").GetUint().ToColor()), readyPlaceBlockPos);
        }
    }
}
